//
//  InHospitalListViewController.m
//  HandheldHospital
//
//  Created by zhangchao on 16/3/4.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "InHospitalListViewController.h"
#import <DOPDropDownMenu.h>
#import "DataManager.h"
#import "PatientData.h"
#import <Masonry.h>


#define kShared [DataManager defaultManager]

@interface InHospitalListViewController ()<DOPDropDownMenuDataSource,DOPDropDownMenuDelegate,UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) DOPDropDownMenu *downMenu;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *tableViewArray;

@end

@implementation InHospitalListViewController

//懒加载
- (NSMutableArray *)tableViewArray
{
    if(_tableViewArray == nil)
    {
        _tableViewArray = [NSMutableArray array];
    }
    return _tableViewArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"住院清单";
    self.tabBarController.tabBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self addViews];
}

//页面布局
- (void)addViews
{
    // 添加下拉菜单
    self.downMenu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, 64) andHeight:44];
    self.downMenu.delegate = self;
    self.downMenu.dataSource = self;
    [self.view addSubview:self.downMenu];
    [self.downMenu selectDefalutIndexPath];
    //添加tableView
    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.downMenu).offset(44);
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(0);
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor redColor];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}

/**
 *  返回 menu 第column列有多少行
 */
- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    return kShared.dataArray.count;
}

/**
 *  返回 menu 第column列 每行title
 */
- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    PatientData *patient = kShared.dataArray[indexPath.row];
    return patient.name;
}



/**
 *  点击代理，点击了第column 第row 或者item项，如果 item >=0
 */
- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath
{
    NSString *str = [NSString stringWithFormat:@"%ld",indexPath.row];
    if(self.tableViewArray.count != 0)
    {
        [self.tableViewArray removeAllObjects];
    }
    [self.tableViewArray addObject:str];
    [self.tableView reloadData];
}

#pragma mark tableView的代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tableViewArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    cell.textLabel.text = self.tableViewArray[indexPath.row];
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
